/**
 * Created by chenyu on 17/10/17.
 */

var Area = require('../models/area');


module.exports = {
    getAllArea: function (req, res) {
        Area.all().then(function (result) {
            res.send(result)
        }, function (error) {
            res.send({status: 400, message: error})
        })
    },
    updateArea: function (req, res) {
        Area.update({region_name: req.body.region_name}, req.body).then(function (result) {
            res.send(result)
        }, function (error) {
            res.send({status: false, message: error})
        })
    },
    addArea: function (req, res) {
        Area.create(req.body).then(function (result) {
            if (result.status === false) {
                return res.send({status: false, message: '失败'})
            }
            res.send(result)
        },function (error) {
            if (error) {
                return res.send({status: false, message: error})
            }
        })
    },
    deleteArea: function (req, res) {
        Area.delete(req.body.region_name).then(function (result) {
            if (result.status === false) {
                return res.send({status: false, message: '失败'})
            }
            res.send(result)
        },function (error) {
            if (error) {
                return res.send({status: false, message: error})
            }
        })
    }
};